#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//to save the data
struct pair{
  int value;
  int num;
};
//MAX data of pairs
#define MAX 1005
//input data head
static struct pair head[MAX];
//output data out
static struct pair out[MAX*2];
static int pos = 0,total = 0;
int outindex = 0;
int linelen =0;
int tvalue,tnum;
void output(void);
void init(struct pair pairs[])
{
  int i=0;
  for(i=0;i<MAX;i++)
    {
      pairs[i].num=0;
      pairs[i].value=0;
    }
}
int main(int argc,char* argv[])
{
  int i,j,k;
  while(EOF!=scanf("%d",&linelen))
    {
      if(linelen==0)break;
      printf("%d\n",linelen);
      i=0;
      while(EOF!=scanf("%d%d",&tvalue,&tnum))
	{
	  if(tnum==0&&tvalue==0)
	    break;
	  head[i].value = tvalue;
	  head[i].num = tnum;
	  i++;
	  total+=tnum;
	}
      head[i].value = 0;
      head[i].num=0;
      output();
      myprint(out);
      outindex=0;
      pos=0;
      total=0;
      init(out);
    }
  printf("0\n");
  return 0;
}
#define MAIN 0
#define INDEX 0
#define LT 1
#define MT 2
#define RT 3
#define LM 4
#define RM 5
#define LB 6
#define MB 7
#define RB 8

int __getnumgo(int* index, int* num)
{
  int result;
  if((*num)==0)
    {
      return -1;
    }
  if(head[*index].num==0)
    return EOF;
  result = head[*index].value;
  (*num)++;
  if(*num>head[*index].num)
    {
      (*num) = 1;
      (*index)++;
    }
  return result;  
}
int __addnum(int value)
{
  if(out[outindex].value==value)
    {
      out[outindex].num++;
      return 0;
    }
  if(out[outindex].num==0)
    {
      out[outindex].num++;
      out[outindex].value = value;
      return 0;
    }
  outindex++;
  __addnum(value);
  return 0;
}
int __calresult(int* outint)
{
  int i,result=0;
  int t;
  for(i=1;i<9;i++)
    {
      if(*(outint+i)==-1)
	{
	  continue;
	}
      int t = abs(*(outint+i)-*outint);
      if(t>result)
	{
	  result = t;
	}
    }
  return result;
}

int myprint(struct pair toprint[])
{
  int index=0;
  for(index=0;toprint[index].num!=0;index++)
    {
      printf("%d %d\n",toprint[index].value,toprint[index].num);
    }
  printf("0 0\n");
}
void __getpos(int pos,int* gindex,int* gp )
{
  int i,j;
  (*gindex)=0;
  (*gp)=1;
  for(i=0;i<pos;i++)
    {
      if(head[*gindex].num-*gp>0)
	(*gp)+=1;
      else
	{
	  (*gindex)+=1;
	  (*gp) = 1;
	}
    }
  return;
}

int __cmpint(const void* a,const void *b)
{
  return *(int*)a-*(int*)b;
}
void output()
{
  //
}
